<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="/css/loginIndex.css">
    <title>登录页面</title>
</head>
<body>
<div class="container">
    <h1>登录</h1>
    <form action="/login">
        <label for="id"><b>用户id</b></label>
        <input type="text" placeholder="输入用户id" id="id" name="id" required>
        <label for="password"><b>密码</b></label>
        <input type="password" placeholder="输入密码" id="password" name="password" required>
        <button type="submit">登录</button>
    </form>
    <div class="register-container">
        <button onclick="location.href='/register.html'">注册</button>
    </div>
    <div class="reset-password">
        <a href="#" id="resetLink">点击我重置密码！</a>
    </div>
</div>
<!-- 新添加的重置密码部分 -->

<script>
    document.getElementById('resetLink').addEventListener('click', function() {
        var userId = document.getElementById('id').value; // 获取用户输入的id
        if(userId==""){
            alert("请先输入您的学号！")
        }else
        {
            // 发送userId到后端Java方法中进行密码重置
            resetPassword(userId);
        }
    });
    function resetPassword(userId) {
        // Java方法中根据userId重置密码为默认密码
        // 例如：默认密码为'linnan' + userId后四位数字
        // 重置成功后给出提示
        if(confirm("学号为"+userId+"的用户，您确认要重置密码吗?请谨慎操作！")){
            location.href="resetPass?userId="+userId;
        }

        var defaultPassword = 'linnan' + userId.slice(-4);
        alert('密码已重置为：' + defaultPassword);
    }
</script>
</body>
</html>